<div id="wrap">
	<div class="title"><?php echo $self['title']?></div>
	<div class="main">
		<div class="list">
			<div id="all-add" class="clearfix">
				<p class="zhu">输入帖子id,状态取反</p>
				<div class="l">
					<p class="tt">添加置顶</p>
				<!--<form method="post">-->
					<input class="sm-input" type="text" placeholder="帖子id" id="cc1"><button id="top" name="top">设置</button>
				<!--</form>-->
				</div>
				<div class="l">
					<p class="tt">添加史诗</p>
				<!--<form method="post">-->
					<input class="sm-input" type="text" placeholder="帖子id" id="cc2"><button id="great" name="great">设置</button>
				<!--</form>-->
				</div>
			</div>
			<div class="tt">
				<span>帖子列表</span>
			<select id="zone">
				<option value="0" selected>所有帖子</option>
			<?php foreach($list as $list_item){ 
				if($list_item['module']){ ?>
				<optgroup label="<?php echo $list_item['name']?>">
				<?php foreach($list_item['module'] as $item){ ?>
					<option value="<?php echo $item['id']?>"><?php echo $item['name']?></option>
				<?php } ?>
				</optgroup>
			<?php } 
			} ?>
			</select>
			</div>
			<ul id="page"></ul>
			<table class="content">
				<thead>
					<tr><th>id</th><th>所属版面</th><th>标题</th><th>作者</th><th>时间</th><th>操作</th></tr>
				</thead>
				<tbody id="tbody">
					
				</tbody>
			</table>
		</div>
	</div>
</div>
</body>
<script type="text/javascript">
  function ajax(url,fun){
  	let xmlhttp = new XMLHttpRequest();
  	xmlhttp.onreadystatechange = fun;
	xmlhttp.open("GET",url,true);
	xmlhttp.send();
  }
  let tbody = document.getElementById('tbody');
  let zone = document.getElementById('zone');
  let page = document.getElementById('page');
  let all_add = document.getElementById('all-add');
  ajax("content_page.php?id="+zone.value,function() {
	    if(this.readyState==4 && this.status==200) {
	    	let data = JSON.parse(this.response);
	    	tbody.innerHTML = data.html;
	    	page.innerHTML = data.page;
	    }
  	});
  all_add.onclick = function(event){
      let sure = false,
          fcc = null;
  	 if(event.target.id == 'top'){
  	     sure = true;
  	     let cc1 = document.getElementById('cc1');
  	     if(cc1.value.length == 0){
  	         cc1.focus();
  	         return
  	     }
  	     fcc = cc1;
  	     
  	 }else if(event.target.id == 'great'){
  	     sure = true;
  	     let cc2 = document.getElementById('cc2');
  	     if(cc2.value.length == 0){
  	         cc2.focus();
  	         return
  	     }
  	     fcc = cc2;
  	 }
  	 if(sure){
  	     ajax("ud.php?type=6&"+event.target.id+"=1&cid="+fcc.value,function() {
    	    if(this.readyState==4 && this.status==200) {
    	        fcc.value = '';
    	    	alert('设置成功')
    	    }
      	});
  	     
  	 }
  	
  }
  zone.onchange = function(){
  	ajax("content_page.php?id="+this.value,function() {
	    if(this.readyState==4 && this.status==200) {
	    	let data = JSON.parse(this.response);
	    	tbody.innerHTML = data.html;
	    	page.innerHTML = data.page;
	    }
  	});
  }
  page.onclick = function(e){
  	let href = e.target.getAttribute('href');
  	if(!/page=\d+/.test(href)){
  		return
  	}
  	ajax(href,function() {
	    if(this.readyState==4 && this.status==200) {
	    	let data = JSON.parse(this.response);
	    	tbody.innerHTML = data.html;
	    	page.innerHTML = data.page;
	    }
  	});
  	return false;
  }
  tbody.onclick = function(e){
  	let id = e.target.getAttribute('id');
  	if(!/^\d+$/.test(id)){
 		return
 	}
  	if(confirm('您确定要删除吗?')){
	  	ajax(`del.php?type=4&id=${id}`,function() {
		    if(this.readyState==4 && this.status==200) {
		    	let {res} = JSON.parse(this.response);
		      	if(res){
		      		window.location.reload();
		      	}
		    }
	  	});
  	}
  }
</script>
</html>